/*
 *  Copyright (C) 2009  Peter Kist & Jan Ripke
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <iostream>

#include <galaxy/Galaxy.h>
#include <galaxy/AppContext.h>

#include <core/Logger.h>
#include <mediator/InterMediator.h>

using namespace std;
using namespace galaxy;

#if _WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT nCmdShow)
#else
int main(int argc, char **argv)
#endif
{
    Galaxy * galaxy  = new Galaxy();
    AppContext& appContext = AppContext::singleton();

#if _WIN32
    appContext.hInstance = hInst;
    appContext.nCmdShow = nCmdShow;
#endif
    appContext.game = galaxy;

    appContext.paths.loadIniFile ();

    core::Logger::initialize ((appContext.paths.logs / "galaxy.log").string().c_str());
    mediator::InterMediator::initialize();

    try {

        galaxy->run ();

    } catch (exception& e) {
        cerr << "error: " << e.what() << endl;
        return 1;
    } catch (...) {
        cerr << "unknown exception!" << endl;
        return 1;
    }

    mediator::InterMediator::terminate();
    core::Logger::terminate();

    return 0;
}